let http = require("http");
let mysql = require("mysql");

http.createServer((req,res)=>{
    res.setHeader("Access-Control-Allow-Origin", "*")//跨域
    res.setHeader('Content-Type', 'text/html; charset=utf-8');//设置乱码
    var connection = mysql.createConnection({     
        host     : 'localhost',       
        user     : 'root',              
        password : 'root',       
        port: '3306',                   
        database: 'web' 
      }); 
       
      connection.connect();
      let person = {
        name:"张三",
        phone:"18220550309"
      } 

      let  sql = `INSERT INTO web50 (id,name,phone) VALUES (NULL,"${person.name}","${person.phone}")`;
      //查
      connection.query(sql,(err,result)=>{
            if(err){
                console.log(err);
                return ;
            }else{
                console.log(666);
                let data = {
                    code:200,
                    msg:"插入成功",
                    data:result
                }
                res.end(JSON.stringify(data))
            }
      });
       
      connection.end();
}).listen(3000)

